let vm = process.env.NODE_ENV === 'production' ? require('@/main-prod.js') : require('@/main-dev.js')

var bgColor = "";//背景
var upColor//涨颜色
var downColor//跌颜色
if (sessionStorage.getItem("color")=='RedRose') { 
	 // eslint-disable-next-line no-mixed-spaces-and-tabs
	upColor="#DD3F3F";//涨颜色
	downColor="#15A76B";//跌颜色
} else {
	upColor="#15A76B";//跌颜色
	downColor="#DD3F3F";//涨颜色
}
// ma  颜色
var ma5Color = "#39afe6";
var ma10Color = "#da6ee8";
var ma20Color = "#ffab42";
var ma30Color = "#00940b";

/**
 * 15:20 时:分 格式时间增加num分钟
 * @param {Object} time 起始时间
 * @param {Object} num
 */
function addTimeStr(time,num){
	var hour=time.split(':')[0];
	var mins=Number(time.split(':')[1]);
	var mins_un=parseInt((mins+num)/60);
	var hour_un=parseInt((Number(hour)+mins_un)/24);
	
	if(mins_un>0){
		if(hour_un>0){
			var tmpVal=((Number(hour)+mins_un)%24)+"";
			hour=tmpVal.length>1? tmpVal:'0'+tmpVal;//判断是否是一位
		}else{
			var tmpVal=Number(hour)+mins_un+"";
			hour=tmpVal.length>1? tmpVal:'0'+tmpVal;
		}
		var tmpMinsVal=((mins+num)%60)+"";
		mins=tmpMinsVal.length>1? tmpMinsVal:0+tmpMinsVal;//分钟数为 取余60的数
	}else{
		var tmpMinsVal=mins+num+"";
		mins=tmpMinsVal.length>1? tmpMinsVal:'0'+tmpMinsVal;//不大于整除60
	}
	return hour+":"+mins;
}

var get_m_data = function(m_data) {
	//console.log(m_data,'mdata')
	var priceArr = new Array();
	var avgPrice = new Array();
	var vol = new Array();
	var times = new Array();
	var volume = new Array();
	// var times = time_arr(type);
	$.each(m_data.data, function(i, v) {
		priceArr.push(v[1]);
		avgPrice.push(v[2]);
		vol.push(v[3]);
		volume.push(v[4]);
		times.push(v[0]);
	})
	return {
		priceArr: priceArr,
		avgPrice: avgPrice,
		vol: vol,
		times: times,
		volume:volume,
		min:Math.min.apply(null,priceArr),
		max:Math.max.apply(null,priceArr),
		yestclose:m_data.yestclose,
	}
}
/**
 * 不同类型的股票的交易时间会不同
 * @param {Object} type   hs=沪深  us=美股  hk=港股
 */
var time_arr = function (type) {
	if((type.toLowerCase()).indexOf('us')!=-1){//生成美股时间段
		var timeArr = new Array();
		timeArr.push('09:30')
		return getNextTime('09:30', '16:00', 2, timeArr);
	}
	if((type.toLowerCase()).indexOf('hs')!=-1){//生成沪深时间段
		var timeArr = new Array();
			timeArr.push('09:30');
			timeArr.concat(getNextTime('09:30', '11:29', 1, timeArr));
			timeArr.push('13:00');
			timeArr.concat(getNextTime('13:00', '15:00', 1, timeArr));
		return timeArr;
	}
	if((type.toLowerCase())=='hk'){//生成港股时间段
		var timeArr = new Array();
			timeArr.push('09:30');
			timeArr.concat(getNextTime('09:30', '11:59', 1, timeArr));
			timeArr.push('13:00');
			timeArr.concat(getNextTime('13:00', '16:00', 1, timeArr));
		return timeArr;
	}

}
//获取增加指定分钟数的 数组  如 09:30增加2分钟  结果为 ['09:31','09:32']
function getNextTime(startTime, endTIme, offset, resultArr) {
	var result = addTimeStr(startTime, offset);
	resultArr.push(result);
	if (result == endTIme) {
		return resultArr;
	} else {
		return getNextTime(result, endTIme, offset, resultArr);
	}
}
/**
 * 计算价格涨跌幅百分比
 * @param {Object} price 当前价
 * @param {Object} yclose 昨收价
 */
function ratioCalculate(price,yclose){
	// console.log(price,yclose,'111111')
	return ((price-yclose)/yclose*100).toFixed(3);
}
/**
 * 生成分时option
 * @param {Object} m_data 分时数据
 * @param {Object} type 股票类型  us-美股  hs-沪深  hk-港股
 */

  function moneyList(val) { 
    val = Number(val)
    if (localStorage.getItem("lang")=='zh') { 
        if (val>=100000000) { 
            return (val/100000000).toFixed(2) + vm.$i18n.t("m.Billion")
        } else if (val<100000000 && val >=1000000) {
            return (val/1000000).toFixed(2) + vm.$i18n.t("m.Ten_thousand")
        } else if(val <1000000 && val >=10000){
            return (val/10000).toFixed(2) + vm.$i18n.t("m.Kill")
        } else {
            return (val).toFixed(2)
        }
    } else {
        if (val>=1000000000) { 
            return (val/1000000000).toFixed(2) + vm.$i18n.t("m.Billion")
        } else if (val<1000000000 && val >=1000000) {
            return (val/1000000).toFixed(2) + vm.$i18n.t("m.Ten_thousand")
        } else if(val <1000000 && val >=10000){
            return (val/1000).toFixed(2) + vm.$i18n.t("m.Kill")
        } else {
            return (val).toFixed(2)
        }
    }
    
}
export function initMOption(m_data) {
	var m_datas = get_m_data(m_data);
	return {
		tooltip: { //弹框指示器
			trigger: 'axis',
			axisPointer: {
				type: 'cross'
			},
			formatter: function (params, ticket, callback) {
				var i = params[0].dataIndex;
		// 		priceArr.push(v[1]);
		// avgPrice.push(v[2]);
		// vol.push(v[3]);
		// times.push(v[0]);
				var color;
				if (m_datas.priceArr[i] > m_data.yestclose) {
					color ='style="color:'+upColor+'"';
				} else {
					color ='style="color:'+downColor+'"';
				}
				var vals = moneyList(Number(m_datas.volume[i]))
				var html = '<div class="commColor" style=""><div>'+vm.$i18n.t('m.Current_price')+' <span  '+color+' >' + Number(m_datas.priceArr[i]).toFixed(2) + '</span></div>';
				html += '<div>'+vm.$i18n.t('m.Average_price')+' <span  '+color+' >' + Number(m_datas.avgPrice[i]).toFixed(2) + '</span></div>';
				html += '<div>'+vm.$i18n.t('m.Increase')+' <span  '+color+' >' + Number(m_datas.vol[i]).toFixed(2)+ '%</span></div>';
				html += '<div>' + vm.$i18n.t('m.Volume') + ' <span  ' + color + ' >' +
				vals
					+
					'</span></div></div>'
				return html;
			}
		},
		color:['#1b80f2','#db8910','#999'],
		
		legend: { //图例控件,点击图例控制哪些系列不显示
			icon: 'rect',
			type: 'scroll',
			itemWidth: 14,
			itemHeight: 2,
			left: 0,
			top: '1%',
			animation:true,
			data:[
				{
					name:vm.$i18n.t('m.Current_price'),
					textStyle: {
						color: '#1b80f2'
					},
				},
				{
					name:vm.$i18n.t('m.Average_price'),
					textStyle: {
						color: '#db8910'
					}
				}
			],
			textStyle: {
				fontSize: 12,
			}
		},
		axisPointer: {
			show: true,
			type: "none",
			link:[0,1,2]
		},
		grid: [{
				id: 'gd1',
				left: '1%',
				right: '1%',
				height: '77%', //主K线的高度,
				top: '8%'
			},
			{
				id: 'gd2',
				left: '1%',
				right: '1%',
				height: '77%', //主K线的高度,
				top: '8%'
			}, {
				id: 'gd3',
				left: '1%',
				right: '1%',
				top: '85%',
				height: '10%' //交易量图的高度
			}
		],
		xAxis: [ //==== x轴
			{ //主图
				
				gridIndex: 0,
				data: m_datas.times,
				axisLabel: { //label文字设置
					show: false
				},
				splitLine: {
					show: false,
				}
			},
			{
				show:false,
				gridIndex: 1,
				data: m_datas.times,
				axisLabel: { //label文字设置
					show: false
				},
				splitLine: {
					show: false,
				}
			}, { //交易量图
				splitNumber: 2,
				type: 'category',
				gridIndex: 2,
				data: m_datas.times,
				axisLabel: { //label文字设置
					color: '#9b9da9',
					fontSize: 0
				},
			}
		],
		yAxis: [ //y轴
			{
				gridIndex: 0,
				scale: true,
				splitNumber:3,
				axisLabel: { //label文字设置
					inside: true, //label文字朝内对齐
					fontWeight:'bold',
					color:function(val){
						//console.log(val,m_data.yestclose,'2222')
						// if(Number(val)==Number(m_data.yestclose)){
						// }
						// return Number(val)>Number(m_data.yestclose)? upColor:downColor;
						return '#aaa'
					}
				},z:4,splitLine: { //分割线设置
					show: false,
          // lineStyle:{
          //   color: ['#333', '#333'],
          //   width: 1,
          //   type: 'solid'
          // }
					// lineStyle: {
					// 	color: '#181a23'
					// }
				},
				// min: function (value) {
				// 	console.log(m_datas.min,'3333')
				// 	if (m_datas.min>1000) { 
				// 		value.min  = m_datas.min - 20
				// 	}
				// 	return value.min;
				// }
				min:function(value){
					if (m_datas.min>1000) { 
						value.min  = m_datas.min - 1
					}else{
						value.min = m_datas.min
					}
					return value.min;
				},
				max:function(value){
					//console.log(m_datas,'3333')
					value.max  = m_datas.max
					return value.max;
				},
			}, {
				scale: true,  gridIndex: 1, splitNumber:3,
				position: 'right', z: 4,
				axisLabel: { //label文字设置
					color:function(val){
						// if(Number(val)==Number(m_data.yestclose)){
						// }
						// return Number(val)>Number(m_data.yestclose)?upColor:downColor;
						return '#aaa'
					},
					inside: true, //label文字朝内对齐
					fontWeight:'bold',
					formatter:function(val){
						var resul=ratioCalculate(val,m_data.yestclose);
						return  Number(resul).toFixed(2)+' %'}
				},
				min:function(value){
					// if (m_datas.min>1000) { 
					// 	value.min  = (m_datas.min - 1-Number(m_datas.yestclose))/Number(m_datas.yestclose)*100+'%'
					// }else{
					// 	value.min = (m_datas.min -Number(m_datas.yestclose))/Number(m_datas.yestclose)*100+'%'
					// }
					return value.min;
				},
				max:function(value){
					// console.log(value,'value3333')
					//value.max  = (m_datas.max-Number(m_datas.yestclose))/Number(m_datas.yestclose)*100+'%'
					return value.max;
				},
				splitLine: { //分割线设置
					show: false,
					lineStyle: {
						color: '#181a23'
					}
				},
				axisPointer:{show:true,
					label:{
						formatter:function(params){ //计算右边Y轴对应的当前价的涨幅比例
							// console.log(params.value,m_data.yestclose,'11111_first')
							return  ratioCalculate(params.value,m_data.yestclose)+'%';
						}
					}
				}
			}
			, { //交易图
				gridIndex: 2,z:4,
				splitNumber: 3,
				axisLine: {
					onZero: false
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: false
				},
				axisLabel: { //label文字设置
					color: '#c7c7c7',
					show: false,
					inside: true, //label文字朝内对齐
					fontSize: 8
				},
			}
		],
		dataZoom: [

		],
		//animation:false,//禁止动画效果
		backgroundColor: bgColor,
		blendMode: 'source-over',
		series: [{
				name: vm.$i18n.t('m.Current_price'),
				type: 'line',
				data: m_datas.priceArr,
				smooth: true,
				symbol: "none", //中时有小圆点
				lineStyle: {
					normal: {
						opacity: 0.6,
						color: '#448EF6',
						width: 1
					}
				},
				areaStyle: {
					color: {
						type: 'linear',
						x: 0,
						y: 0,
						x2: 0,
						y2: 1,
						colorStops: [{
							offset: 0, color: '#448EF6' // 0% 处的颜色
						}, {
							offset: 0.9, color: 'rgba(0, 0, 0, 0.02)' // 100% 处的颜色
						}],
						global: false // 缺省为 false
					},
						// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						// 	offset: 0,
						// 	color: 'rgba(0, 136, 212, 0.7)'
						// }, {
						// 	offset: 0.8,
						// 	color: 'rgba(0, 136, 212, 0.02)'
						// }], false),
						shadowColor: 'rgba(0, 0, 0, 0.1)',
						shadowBlur: 10
					
				}
			},
			{
				name: vm.$i18n.t('m.Average_price'),
				type: 'line',
				data: m_datas.avgPrice,
				smooth: true,
				symbol: "none",
				lineStyle: { //标线的样式
					normal: {
						opacity: 0.8,
						color: '#db8910',
						width: 1
					}
				}
			},{
				type: 'line',
				data: m_datas.priceArr,	
				smooth: true,
				symbol: "none",
				gridIndex: 1,
				xAxisIndex: 1,
				yAxisIndex: 1,
				lineStyle: { //标线的样式
					normal: {
						width: 0
					}
				}
			},
			{
				name: 'Volumn',
				type: 'bar',
				gridIndex: 2,
				xAxisIndex: 2,
				yAxisIndex: 2,
				data: m_datas.volume,
				barWidth: '60%',
				itemStyle: {
					normal: {
						color: function(params) {
							var colorList;
							if (m_datas.volume[params.dataIndex] > m_datas.volume[params.dataIndex-1]) {
								colorList = upColor;
							} else {
								colorList = downColor;
							}
							return colorList;
						},
					}
				}
			}
		]
	};
}

//数组处理
function splitData(rawData) {
	var datas = []; var times = []; var vols = []; var md5 = []; var md10 = [];var md20=[]
	for (var i = 0; i < rawData.length; i++) {
		datas.push(rawData[i]);
		times.push(rawData[i].splice(0, 1)[0]);
		vols.push(rawData[i][4]);
		md5.push(rawData[i][5]);
		md10.push(rawData[i][6]);
		md20.push(rawData[i][7]);
	}
	return {datas:datas,times:times,vols:vols,md5:md5,md10:md10,md20:md20};
}
function calculateMA(dayCount,data) {
	var result = [];
	for (var i = 0, len = data.times.length; i < len; i++) {
		if (i < dayCount) {
			result.push('-');
			continue;
		}
		var sum = 0;
		for (var j = 0; j < dayCount; j++) {
			sum += data.datas[i - j][1];
		}
		result.push((sum / dayCount).toFixed(2));
	}
	return result;
}

//=================================================MADC计算公式

var calcEMA,calcDIF,calcDEA,calcMACD;

/*
 * 计算EMA指数平滑移动平均线，用于MACD
 * @param {number} n 时间窗口
 * @param {array} data 输入数据
 * @param {string} field 计算字段配置
 */
calcEMA=function(n,data,field){
    var i,l,ema,a;
    a=2/(n+1);
    if(field){
        //二维数组
        ema=[data[0][field]];
        for(i=1,l=data.length;i<l;i++){
            ema.push((a*data[i][field]+(1-a)*ema[i-1]).toFixed(2));
        }
    }else{
        //普通一维数组
        ema=[data[0]];
        for(i=1,l=data.length;i<l;i++){
            ema.push((a*data[i]+(1-a)*ema[i-1]).toFixed(3) );
        }
    }
    return ema;
};

/*
 * 计算DIF快线，用于MACD
 * @param {number} short 快速EMA时间窗口
 * @param {number} long 慢速EMA时间窗口
 * @param {array} data 输入数据
 * @param {string} field 计算字段配置
 */
calcDIF=function(short,long,data,field){
    var i,l,dif,emaShort,emaLong;
    dif=[];
    emaShort=calcEMA(short,data,field);
    emaLong=calcEMA(long,data,field);
    for(i=0,l=data.length;i<l;i++){
        dif.push((emaShort[i]-emaLong[i]).toFixed(3));
    }
    return dif;
};

/*
 * 计算DEA慢线，用于MACD
 * @param {number} mid 对dif的时间窗口
 * @param {array} dif 输入数据
 */
calcDEA=function(mid,dif){
    return calcEMA(mid,dif);
};

/*
 * 计算MACD
 * @param {number} short 快速EMA时间窗口
 * @param {number} long 慢速EMA时间窗口
 * @param {number} mid dea时间窗口
 * @param {array} data 输入数据
 * @param {string} field 计算字段配置
 */
calcMACD=function(short,long,mid,data,field){
    var i,l,dif,dea,macd,result;
    result={};
    macd=[];
    dif=calcDIF(short,long,data,field);
    dea=calcDEA(mid,dif);
    for(i=0,l=data.length;i<l;i++){
        macd.push(((dif[i]-dea[i])*2).toFixed(3));
    }
    result.dif=dif;
    result.dea=dea;
    result.macd=macd;
    return result;
};


 //=================================================MADC计算公式 end


export function initKOption(cdata) {
	//var data = splitData(cdata);
	var data = cdata
	// console.log(data,'initKOption1')
	var macd=calcMACD(12,26,9,data.datas,1);
	return {
		tooltip: { //弹框指示器
			trigger: 'axis',
			axisPointer: {
				type: 'cross'
			},
			position: function (pos, params, dom, rect, size) {
				// 鼠标在左侧时 tooltip 显示到右侧，鼠标在右侧时 tooltip 显示到左侧。
				var obj = {top: 60};
				obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = pos[1]+50;
				// console.log(obj,'initKOption0')
				return obj;
			},
			formatter: function (params) { 
				// eslint-disable-next-line no-unused-vars
				var htmls = ''
				// eslint-disable-next-line no-empty
				if (params.length == 1 && params[0].componentSubType=='bar') {
					if(localStorage.getItem("lang")== "en") {
						var num = Number(params[0].value)>=1000000000?(Number(params[0].value)/100000000).toFixed(2)+'B':(Number(params[0].value)/1000).toFixed(2)+'K'
					}else
					var num = Number(params[0].value)>=1000000000?(Number(params[0].value)/1000000000).toFixed(2)+'亿':(Number(params[0].value)/10000).toFixed(2)+'万'
					htmls = `<div  class="commColor" >
						<div>${params[0].axisValue}<div>
						<div>${vm.$i18n.t('m.Volume')}: ${num}<div>
					<div>`
				// eslint-disable-next-line no-empty
				} else {
					if(params[0].seriesName=='K线周期图表'){
						htmls = `<div  class="KineHtml" style="padding:0 10px;">
						<div>${params[0].name}<div>
						<div>${vm.$i18n.t('m.K_title')}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.OpenToday')}: ${params[0].data[1]}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.Closing_price')}: ${params[0].data[2]}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.lowest')}: ${params[0].data[3]}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.highest')}: ${params[0].data[4]}<div>
					<div>
						`
					}else{
						htmls = htmls + `<div>${params[0].marker}${params[0].seriesName}: ${params[0].data}<div>`
					}
					if (params.length == 4) {
						htmls = htmls + `<div>${params[1].marker}${params[1].seriesName}: ${params[1].data}<div>
						<div>${params[2].marker}${params[2].seriesName}: ${params[2].data}<div>
						<div>${params[3].marker}${params[3].seriesName}: ${params[3].data}<div>`
					} else if (params.length == 3) {
						htmls = htmls + `<div>${params[1].marker}${params[1].seriesName}: ${params[1].data}<div>
						<div>${params[2].marker}${params[2].seriesName}: ${params[2].data}<div>`
					} else if (params.length == 2) {
						htmls = htmls + `<div>${params[1].marker}${params[1].seriesName}: ${params[1].data}<div>`
					} 
				}
				return htmls
			}
		},
		legend: { //图例控件,点击图例控制哪些系列不显示
			icon: 'rect',
			type:'scroll',
			itemWidth: 14,
			itemHeight: 2,
			left: 0,
			top: '0',
			animation:true,
			textStyle: {
				fontSize: 12,
				color: '#0e99e2'
			},
			pageIconColor:'#0e99e2'
		},
		axisPointer: {
			show: true
		},
		color: [ma5Color, ma10Color, ma20Color, ma30Color],
		grid: [{
			id: 'gd1',
			left: '0%',
			right: '1%',
			height: '90%', //主K线的高度,
			top: '5%'
		}, {
			left: '0%',
			right: '1%',
			top: '95%',
			height: '0%' //交易量图的高度
		}
		,{
			left: '0%',
			right: '1%',
			top: '95%', //MACD 指标
			height: '0%'
		}],
		xAxis: [ //==== x轴
			{ //主图
				type: 'category',
				data: data.times,
				scale: true,
				boundaryGap: false,
				axisLine: {
					onZero: false
				},
				axisLabel: { //label文字设置
					show: false
				},
				splitLine: {
					show: false,
					lineStyle: {
						color: '#3a3a3e'
					}
				},
				splitNumber: 20,
				min: 'dataMin',
				max: 'dataMax'
			}, { //交易量图
				type: 'category',
				gridIndex: 1,
				data: data.times,
				axisLabel: { //label文字设置
					color: '#9b9da9',
					fontSize: 10
				},
			}, { //幅图
				type: 'category',
				gridIndex: 2,
				data: data.times,
				axisLabel: {
					show: false
				}
			}
		],
		yAxis: [ //y轴
			{ //==主图
				scale: true,
				z:4,
				axisLabel: { //label文字设置
					color: '#c7c7c7',
					inside: true, //label文字朝内对齐
				},
				splitLine: { //分割线设置
					show: false,
					lineStyle: {
						color: '#181a23'
					}
				},
			}, { //交易图
				gridIndex: 1, splitNumber: 3, z:4,
				axisLine: {
					onZero: false
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: false
				},
				axisLabel: { //label文字设置
					color: '#c7c7c7',
					inside: true, //label文字朝内对齐
					fontSize: 8
				},
			}, { //幅图
				z:4, gridIndex: 2,splitNumber: 4,
				axisLine: {
					onZero: false
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: false
				},
				axisLabel: { //label文字设置
					color: '#c7c7c7',
					inside: true, //label文字朝内对齐
					fontSize: 8
				},
			}
		],
		dataZoom: [
			{
				type: 'slider',
				xAxisIndex: [0, 1, 2], //控件联动
				start: 100,
				end: 80,
				throttle: 10,
				top: '90%',
				height: '3%',
				borderColor: '#696969',
				textStyle: {
					color: '#dcdcdc'
				},
				handleSize: '90%', //滑块图标
				handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
				dataBackground: {
					lineStyle: {
						color: '#fff'
					}, //数据边界线样式
					areaStyle: {
						color: '#696969'
					} //数据域填充样式
				}
			},
					{
						type: 'inside',
						xAxisIndex: [0,1,2],//控件联动
					},
		],
		animation: false, //禁止动画效果
		backgroundColor: bgColor,
		blendMode: 'source-over',
		series: [{
				name: vm.$i18n.t('m.K_title'),
				type: 'candlestick',
				data: data.datas,
				barWidth: '55%',
				large: true,
				largeThreshold: 100,
				itemStyle: {
					normal: {
						color: upColor, //fd2e2e  ff4242
						color0: downColor,
						borderColor: upColor,
						borderColor0: downColor,
					}
				},

			}, {
				name: 'MA5',
				type: 'line',
				data:  data.md5,
				smooth: true,
				symbol: "none", //隐藏选中时有小圆点
				lineStyle: {
					normal: {
						opacity: 0.8,
						color: '#39afe6',
						width: 1
					}
				},
			},
			{
				name: 'MA10',
				type: 'line',
				data: data.md10,
				smooth: true,
				symbol: "none",
				lineStyle: { //标线的样式
					normal: {
						opacity: 0.8,
						color: '#da6ee8',
						width: 1
					}
				}
			},
			{
				name: 'MA20',
				type: 'line',
				data: data.md20,
				// data: calculateMA(20,data),
				smooth: true,
				symbol: "none",
				lineStyle: {
					opacity: 0.8,
					width: 1,
					color: ma20Color
				}
			},
			// {
			// 	name: 'MA30',
			// 	type: 'line',
			// 	data: calculateMA(30,data),
			// 	smooth: true,
			// 	symbol: "none",
			// 	lineStyle: {
			// 		normal: {
			// 			opacity: 0.8,
			// 			width: 1,
			// 			color: ma30Color
			// 		}
			// 	}
			// },
			// {
			// 	name: 'Volumn',
			// 	type: 'bar',
			// 	xAxisIndex: 1,
			// 	yAxisIndex: 1,
			// 	data: data.vols,
			// 	barWidth: '60%',
			// 	itemStyle: {
			// 		normal: {
			// 			color: function(params) {
			// 				var colorList;
			// 				if (data.datas[params.dataIndex][1] > data.datas[params.dataIndex][0]) {
			// 					colorList = upColor;
			// 				} else {
			// 					colorList = downColor;
			// 				}
			// 				return colorList;
			// 			},
			// 		}
			// 	}
			// }
			// , {
			// 	name: 'MACD',
			// 	type: 'bar',
			// 	xAxisIndex: 2,
			// 	yAxisIndex: 2,
			// 	data: macd.macd,
			// 	barWidth: '40%',
			// 	itemStyle: {
			// 		normal: {
			// 			color: function(params) {
			// 				var colorList;
			// 				if (params.data >= 0) {
			// 					colorList = upColor;
			// 				} else {
			// 					colorList = downColor;
			// 				}
			// 				return colorList;
			// 			},
			// 		}
			// 	}
			// }, {
			// 	name: 'DIF',
			// 	type: 'line',
			// 	symbol: "none",
			// 	xAxisIndex: 2,
			// 	yAxisIndex: 2,
			// 	data: macd.dif,
			// 	lineStyle: {
			// 		normal: {
			// 			color: '#da6ee8',
			// 			width: 1
			// 		}
			// 	}
			// }, {
			// 	name: 'DEA',
			// 	type: 'line',
			// 	symbol: "none",
			// 	xAxisIndex: 2,
			// 	yAxisIndex: 2,
			// 	data: macd.dea,
			// 	lineStyle: {
			// 		normal: {
			// 			opacity: 0.8,
			// 			color: '#39afe6',
			// 			width: 1
			// 		}
			// 	}
			// }
		]
	};
}
export function initKOptionVolume(cdata) {
	//var data = splitData(cdata);
	var data = cdata
	// console.log(data,'initKOption2')
	var macd=calcMACD(12,26,9,data.datas,1);
	return {
		tooltip: { //弹框指示器
			trigger: 'axis',
			axisPointer: {
				type: 'cross'
			},
			position: function (pos, params, dom, rect, size) {
				// 鼠标在左侧时 tooltip 显示到右侧，鼠标在右侧时 tooltip 显示到左侧。
				var obj = {top: 1};
				obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = pos[1]+50;
				return obj;
			},
			formatter: function (params) { 
				// eslint-disable-next-line no-unused-vars
				var htmls = ''
				// eslint-disable-next-line no-empty
				if (params.length == 1 && params[0].componentSubType=='bar') {
					if(localStorage.getItem("lang")== "en") {
						var num = Number(params[0].value)>=1000000000?(Number(params[0].value)/100000000).toFixed(2)+'B':(Number(params[0].value)/1000).toFixed(2)+'K'
					}else
					var num = Number(params[0].value)>=1000000000?(Number(params[0].value)/1000000000).toFixed(2)+'亿':(Number(params[0].value)/10000).toFixed(2)+'万'
					htmls = `<div  class="commColor" >
						<div>${params[0].axisValue}<div>
						<div>${vm.$i18n.t('m.Volume')}: ${num}<div>
					<div>`
				// eslint-disable-next-line no-empty
				} else {
					if(params[0].seriesName=='K线周期图表'){
						htmls = `<div  class="KineHtml" style="padding:0 10px;">
						<div>${params[0].name}<div>
						<div>${vm.$i18n.t('m.K_title')}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.OpenToday')}: ${params[0].data[1]}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.Closing_price')}: ${params[0].data[2]}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.lowest')}: ${params[0].data[3]}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.highest')}: ${params[0].data[4]}<div>
					<div>
						`
					}else{
						htmls = htmls + `<div>${params[0].marker}${params[0].seriesName}: ${params[0].data}<div>`
					}
					if (params.length == 4) {
						htmls = htmls + `<div>${params[1].marker}${params[1].seriesName}: ${params[1].data}<div>
						<div>${params[2].marker}${params[2].seriesName}: ${params[2].data}<div>
						<div>${params[3].marker}${params[3].seriesName}: ${params[3].data}<div>`
					} else if (params.length == 3) {
						htmls = htmls + `<div>${params[1].marker}${params[1].seriesName}: ${params[1].data}<div>
						<div>${params[2].marker}${params[2].seriesName}: ${params[2].data}<div>`
					} else if (params.length == 2) {
						htmls = htmls + `<div>${params[1].marker}${params[1].seriesName}: ${params[1].data}<div>`
					} 
				}
				return htmls
			}
		},
		legend: { //图例控件,点击图例控制哪些系列不显示
			icon: 'rect',
			type:'scroll',
			itemWidth: 14,
			itemHeight: 2,
			left: 0,
			top: '-2%',
			animation:true,
			textStyle: {
				fontSize: 12,
				color: '#0e99e2'
			},
			pageIconColor:'#0e99e2'
		},
		axisPointer: {
			show: true
		},
		color: [ma5Color, ma10Color, ma20Color, ma30Color],
		grid: [{
			id: 'gd1',
			left: '0%',
			right: '1%',
			height: '0%', //主K线的高度,
			top: '10%'
		}, {
			left: '0%',
			right: '1%',
			top: '20%',
			height: '60%' //交易量图的高度
		}
		,{
			left: '0%',
			right: '1%',
			top: '80%', //MACD 指标
			height: '0%'
		}],
		xAxis: [ //==== x轴
			{ //主图
				type: 'category',
				data: data.times,
				scale: true,
				boundaryGap: false,
				axisLine: {
					onZero: false
				},
				axisLabel: { //label文字设置
					show: false
				},
				splitLine: {
					show: false,
					lineStyle: {
						color: '#3a3a3e'
					}
				},
				splitNumber: 20,
				min: 'dataMin',
				max: 'dataMax'
			}, { //交易量图
				type: 'category',
				gridIndex: 1,
				data: data.times,
				axisLabel: { //label文字设置
					color: '#9b9da9',
					fontSize: 10
				},
			}, { //幅图
				type: 'category',
				gridIndex: 2,
				data: data.times,
				axisLabel: {
					show: false
				}
			}
		],
		yAxis: [ //y轴
			{ //==主图
				scale: true,
				z:4,
				axisLabel: { //label文字设置
					color: '#c7c7c7',
					inside: true, //label文字朝内对齐
				},
				splitLine: { //分割线设置
					show: false,
					lineStyle: {
						color: '#181a23'
					}
				},
			}, { //交易图
				gridIndex: 1, splitNumber: 3, z:4,
				axisLine: {
					onZero: false
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: false
				},
				axisLabel: { //label文字设置
					color: '#c7c7c7',
					inside: true, //label文字朝内对齐
					fontSize: 8
				},
			}, { //幅图
				z:4, gridIndex: 2,splitNumber: 4,
				axisLine: {
					onZero: false
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: false
				},
				axisLabel: { //label文字设置
					color: '#c7c7c7',
					inside: true, //label文字朝内对齐
					fontSize: 8
				},
			}
		],
		dataZoom: [
			{
				type: 'slider',
				xAxisIndex: [0, 1, 2], //控件联动
				start: 100,
				end: 80,
				throttle: 10,
				top: '94%',
				height: '6%',
				borderColor: '#696969',
				textStyle: {
					color: '#dcdcdc'
				},
				handleSize: '90%', //滑块图标
				handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
				dataBackground: {
					lineStyle: {
						color: '#fff'
					}, //数据边界线样式
					areaStyle: {
						color: '#696969'
					} //数据域填充样式
				}
			},
					{
						type: 'inside',
						xAxisIndex: [0,1,2],//控件联动
					},
		],
		animation: false, //禁止动画效果
		backgroundColor: bgColor,
		blendMode: 'source-over',
		series: [{
				name: 'Volumn',
				type: 'bar',
				xAxisIndex: 1,
				yAxisIndex: 1,
				data: data.vols,
				barWidth: '60%',
				itemStyle: {
					normal: {
						color: function(params) {
							var colorList;
							if (data.datas[params.dataIndex][1] > data.datas[params.dataIndex][0]) {
								colorList = upColor;
							} else {
								colorList = downColor;
							}
							return colorList;
						},
					}
				}
			}
		]
	};
}
export function initKOptionMACD(cdata) {
	//var data = splitData(cdata);
	var data = cdata
	var macd=calcMACD(12,26,9,data.datas,1);
	return {
		tooltip: { //弹框指示器
			trigger: 'axis',
			axisPointer: {
				type: 'cross'
			},
			position: function (pos, params, dom, rect, size) {
				// 鼠标在左侧时 tooltip 显示到右侧，鼠标在右侧时 tooltip 显示到左侧。
				var obj = {top: 1};
				obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = pos[1]+50;
				return obj;
			},
			formatter: function (params) { 
				// eslint-disable-next-line no-unused-vars
				var htmls = ''
				// eslint-disable-next-line no-empty
				if (params.length == 1 && params[0].componentSubType=='bar') { 
					if(localStorage.getItem("lang")== "en") {
						var num = Number(params[0].value)>=1000000000?(Number(params[0].value)/100000000).toFixed(2)+'B':(Number(params[0].value)/1000).toFixed(2)+'K'
					}else
					var num = Number(params[0].value)>=1000000000?(Number(params[0].value)/1000000000).toFixed(2)+'亿':(Number(params[0].value)/10000).toFixed(2)+'万'
					htmls = `<div  class="commColor" >
						<div>${params[0].axisValue}<div>
						<div>${vm.$i18n.t('m.Volume')}: ${num}<div>
					<div>`
				// eslint-disable-next-line no-empty
				} else {
					if(params[0].seriesName=='K线周期图表'){
						htmls = `<div  class="KineHtml" style="padding:0 10px;">
						<div>${params[0].name}<div>
						<div>${vm.$i18n.t('m.K_title')}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.OpenToday')}: ${params[0].data[1]}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.Closing_price')}: ${params[0].data[2]}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.lowest')}: ${params[0].data[3]}<div>
						<div>${params[0].marker}${vm.$i18n.t('m.highest')}: ${params[0].data[4]}<div>
					<div>
						`
					}else{
						htmls = htmls + `<div>${params[0].marker}${params[0].seriesName}: ${params[0].data}<div>`
					}
					if (params.length == 4) {
						htmls = htmls + `<div>${params[1].marker}${params[1].seriesName}: ${params[1].data}<div>
						<div>${params[2].marker}${params[2].seriesName}: ${params[2].data}<div>
						<div>${params[3].marker}${params[3].seriesName}: ${params[3].data}<div>`
					} else if (params.length == 3) {
						htmls = htmls + `<div>${params[1].marker}${params[1].seriesName}: ${params[1].data}<div>
						<div>${params[2].marker}${params[2].seriesName}: ${params[2].data}<div>`
					} else if (params.length == 2) {
						htmls = htmls + `<div>${params[1].marker}${params[1].seriesName}: ${params[1].data}<div>`
					} 
				}
				return htmls
			}
		},
		legend: { //图例控件,点击图例控制哪些系列不显示
			icon: 'rect',
			type:'scroll',
			itemWidth: 14,
			itemHeight: 2,
			left: 0,
			top: '0',
			animation:true,
			textStyle: {
				fontSize: 12,
				color: '#0e99e2'
			},
			pageIconColor:'#0e99e2'
		},
		axisPointer: {
			show: true
		},
		color: [ma5Color, ma10Color, ma20Color, ma30Color],
		grid: [{
			id: 'gd1',
			left: '0%',
			right: '1%',
			height: '0%', //主K线的高度,
			top: '0%'
		}, {
			left: '0%',
			right: '1%',
			top: '80%',
			height: '0%' //交易量图的高度
		}
		,{
			left: '0%',
			right: '1%',
			top: '20%', //MACD 指标
			height: '60%'
		}],
		xAxis: [ //==== x轴
			{ //主图
				type: 'category',
				data: data.times,
				scale: true,
				boundaryGap: false,
				axisLine: {
					onZero: false
				},
				axisLabel: { //label文字设置
					show: false
				},
				splitLine: {
					show: false,
					lineStyle: {
						color: '#3a3a3e'
					}
				},
				splitNumber: 20,
				min: 'dataMin',
				max: 'dataMax'
			}, { //交易量图
				type: 'category',
				gridIndex: 1,
				data: data.times,
				axisLabel: { //label文字设置
					color: '#9b9da9',
					fontSize: 10
				},
			}, { //幅图
				type: 'category',
				gridIndex: 2,
				data: data.times,
				axisLabel: {
					show: false
				}
			}
		],
		yAxis: [ //y轴
			{ //==主图
				scale: true,
				z:4,
				axisLabel: { //label文字设置
					color: '#c7c7c7',
					inside: true, //label文字朝内对齐
				},
				splitLine: { //分割线设置
					show: false,
					lineStyle: {
						color: '#181a23'
					}
				},
			}, { //交易图
				gridIndex: 1, splitNumber: 3, z:4,
				axisLine: {
					onZero: false
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: false
				},
				axisLabel: { //label文字设置
					color: '#c7c7c7',
					inside: true, //label文字朝内对齐
					fontSize: 8
				},
			}, { //幅图
				z:4, gridIndex: 2,splitNumber: 4,
				axisLine: {
					onZero: false
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: false
				},
				axisLabel: { //label文字设置
					color: '#c7c7c7',
					inside: true, //label文字朝内对齐
					fontSize: 8
				},
			}
		],
		dataZoom: [
			{
				type: 'slider',
				xAxisIndex: [0, 1, 2], //控件联动
				start: 100,
				end: 80,
				throttle: 10,
				top: '94%',
				height: '6%',
				borderColor: '#696969',
				textStyle: {
					color: '#dcdcdc'
				},
				handleSize: '90%', //滑块图标
				handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
				dataBackground: {
					lineStyle: {
						color: '#fff'
					}, //数据边界线样式
					areaStyle: {
						color: '#696969'
					} //数据域填充样式
				}
			},
					{
						type: 'inside',
						xAxisIndex: [0,1,2],//控件联动
					},
		],
		animation: false, //禁止动画效果
		backgroundColor: bgColor,
		blendMode: 'source-over',
		series: [ {
				name: 'MACD',
				type: 'bar',
				xAxisIndex: 2,
				yAxisIndex: 2,
				data: macd.macd,
				barWidth: '40%',
				itemStyle: {
					normal: {
						color: function(params) {
							var colorList;
							if (params.data >= 0) {
								colorList = upColor;
							} else {
								colorList = downColor;
							}
							return colorList;
						},
					}
				}
			}, {
				name: 'DIF',
				type: 'line',
				symbol: "none",
				xAxisIndex: 2,
				yAxisIndex: 2,
				data: macd.dif,
				lineStyle: {
					normal: {
						color: '#da6ee8',
						width: 1
					}
				}
			}, {
				name: 'DEA',
				type: 'line',
				symbol: "none",
				xAxisIndex: 2,
				yAxisIndex: 2,
				data: macd.dea,
				lineStyle: {
					normal: {
						opacity: 0.8,
						color: '#39afe6',
						width: 1
					}
				}
			}
		]
	};
}